package com.cjl.dental_clinic.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.conditions.update.UpdateChainWrapper;
import com.cjl.dental_clinic.base.BaseController;
import com.cjl.dental_clinic.base.ResVo;
import com.cjl.dental_clinic.entity.Doctor;
import com.cjl.dental_clinic.service.DoctorService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @description:
 * @author: cjl
 * @time: 2024/03/12 14:37
 */
@RestController
@RequestMapping("/cjl/doctor")
public class DoctorController extends BaseController<Doctor, DoctorService> {
    public DoctorController(DoctorService baseService) {
        super(baseService);
    }

    /**
     * 医生列表
     * @return
     */
    @PostMapping("list")
    public ResVo<List<Doctor>> DoctorList() {
        return ResVo.ok(baseService.list());
    }

    /**
     * 删除医生
     * @param id
     * @return
     */
    @PostMapping("del")
    public ResVo<Boolean> DoctorDel(Integer id) {
        return ResVo.ok(baseService.removeById(id));
    }

    /**
     * 修改状态
     * @param id
     * @return
     */
    @PostMapping("updateStatus")
    public ResVo<Boolean> DoctorSave(Integer id) {
        return ResVo.ok(baseService.updateStatus(id));
    }

    /**
     * 保存医生
     * @param doctor
     * @return
     */
    @PostMapping("saveDoctor")
    public ResVo<Boolean> saveDoctor(Doctor doctor) {
        doctor.initCreateUser();
        return ResVo.ok(baseService.save(doctor));
    }

    /**
     * 修改医生
     * @param doctor
     * @return
     */
    @PostMapping("updateDoctor")
    public ResVo<Boolean> updateDoctor(Doctor doctor) {
        return ResVo.ok(baseService.updateById(doctor));
    }

    /**
     * 搜索医生
     * @param name
     * @return
     */
    @PostMapping("search")
    public ResVo<List<Doctor>> search(String name) {
        QueryWrapper<Doctor> queryWrapper = new QueryWrapper<>();
        queryWrapper.like("name", name);
        return ResVo.ok(baseService.list(queryWrapper));
    }
    /**
     * 根据状态获取医生列表
     */
    @PostMapping("type")
    public ResVo<List<Doctor>> type(Integer type){
        return ResVo.ok(baseService.list(new QueryWrapper<Doctor>().eq("status",type)));
    }
}
